package cn.eeepay.boss.action.aatAgentActivity;

import cn.eeepay.boss.system.DataSource;
import cn.eeepay.boss.system.SystemLog;
import cn.eeepay.framework.db.pagination.Page;
import cn.eeepay.framework.model.aatAgentActivity.AgentRewardRecord;
import cn.eeepay.framework.service.aatAgentActivity.AgentRewardRecordService;
import cn.eeepay.framework.util.Constants;
import cn.eeepay.framework.util.ExportResult;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping(value = "/agentRewardRecordAction")
public class AgentRewardRecordAction {

    private static final Logger log = LoggerFactory.getLogger(AppMenuAction.class);

    @Resource
    private AgentRewardRecordService agentRewardRecordService;

    /**
     * 查询列表
     */
    @RequestMapping(value = "/selectAll")
    @ResponseBody
    @DataSource(Constants.DATA_SOURCE_SLAVE)
    public Map<String,Object> selectByParam(@RequestParam("info") String param, @ModelAttribute("page") Page<AgentRewardRecord> page){
        Map<String, Object> msg=new HashMap<String,Object>();
        try{
            AgentRewardRecord info = JSONObject.parseObject(param, AgentRewardRecord.class);
            agentRewardRecordService.selectAllList(info, page);
            msg.put("page",page);
            msg.put("status", true);
        } catch (Exception e){
            log.error("查询列表异常!",e);
            msg.put("status", false);
            msg.put("msg", "查询列表异常!");
        }
        return msg;
    }
    /**
     * 导出领奖列表
     */
    @RequestMapping(value = "/exportExcel")
    @ResponseBody
    @DataSource(Constants.DATA_SOURCE_SLAVE)
    @SystemLog(description = "导出领奖列表",operCode="agentRewardRecordAction.exportExcel")
    public Map<String,Object> exportExcel(@RequestParam("info") String param,HttpServletResponse response){
        Map<String, Object> msg=new HashMap<String,Object>();
        try{
            AgentRewardRecord info = JSONObject.parseObject(param, AgentRewardRecord.class);
            agentRewardRecordService.exportExcel(info,response);
        } catch (Exception e){
            ExportResult.setExportResult(response,false,"导出异常");
            log.error("导出领奖列表异常!",e);
        }
        return msg;
    }
}
